﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Security;

namespace AspAuthentication.Core
{
    /// <summary>
    /// Defines the class DomainUser
    /// </summary>
    public class DomainUser : MembershipUser
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="DomainUser"/> class.
        /// </summary>
        public DomainUser() { }
        /// <summary>
        /// Initializes a new instance of the <see cref="DomainUser"/> class.
        /// </summary>
        /// <param name="providerName">Name of the provider.</param>
        /// <param name="username">The username.</param>
        /// <param name="providerUserKey">The provider user key.</param>
        /// <param name="email">The email.</param>
        /// <param name="passwordQuestion">The password question.</param>
        /// <param name="comment">The comment.</param>
        /// <param name="isApproved">if set to <c>true</c> [is approved].</param>
        /// <param name="isLockedOut">if set to <c>true</c> [is locked out].</param>
        /// <param name="creationDate">The creation date.</param>
        /// <param name="lastLoginDate">The last login date.</param>
        /// <param name="lastActivityDate">The last activity date.</param>
        /// <param name="lastPasswordChangedDate">The last password changed date.</param>
        /// <param name="lastLockoutDate">The last lockout date.</param>
        /// <param name="password">The password.</param>
        /// <param name="passwordAnswer">The password answer.</param>
        public DomainUser(string providerName, string username, object providerUserKey, string email,
                              string passwordQuestion, string comment, bool isApproved, bool isLockedOut,
                              DateTime creationDate, DateTime lastLoginDate, DateTime lastActivityDate,
                              DateTime lastPasswordChangedDate, DateTime lastLockoutDate, string password, string passwordAnswer)
            : base(providerName, username, providerUserKey, email, passwordQuestion, comment, isApproved, isLockedOut, creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockoutDate)
        {
            UserName = username;
            PasswordQuestion = passwordQuestion;
            IsLockedOut = isLockedOut;
            LastLockoutDate = lastLockoutDate;
            CreationDate = creationDate;
            LastPasswordChangedDate = lastPasswordChangedDate;
            ProviderName = providerName;
            Password = password;
            PasswordAnswer = passwordAnswer;
        }

        /// <summary>
        /// Gets to membership user.
        /// </summary>
        /// <value>To membership user.</value>
        public MembershipUser ToMembershipUser
        {
            get
            {
                return new MembershipUser(ProviderName, UserName, UserName, Email, PasswordQuestion, Comment, IsApproved, IsLockedOut, CreationDate, LastLoginDate, LastActivityDate, LastPasswordChangedDate, LastLockoutDate); 
            }
        }

        /// <summary>
        /// Gets the logon name of the membership user.
        /// </summary>
        /// <value></value>
        /// <returns>The logon name of the membership user.</returns>
        [Key, Required, StringLength(50, MinimumLength = 1)]
        public new string UserName { get; set; }
        /// <summary>
        /// Gets the user identifier from the membership data source for the user.
        /// </summary>
        /// <value></value>
        /// <returns>The user identifier from the membership data source for the user.</returns>
        public new string ProviderUserKey{get { return UserName; }}
        /// <summary>
        /// Gets the password question for the membership user.
        /// </summary>
        /// <value></value>
        /// <returns>The password question for the membership user.</returns>
        public new string PasswordQuestion { get; set; }
        /// <summary>
        /// Gets a value indicating whether the membership user is locked out and unable to be validated.
        /// </summary>
        /// <value></value>
        /// <returns>true if the membership user is locked out and unable to be validated; otherwise, false.</returns>
        public new bool IsLockedOut { get; set; }
        /// <summary>
        /// Gets the most recent date and time that the membership user was locked out.
        /// </summary>
        /// <value></value>
        /// <returns>A <see cref="T:System.DateTime"/> object that represents the most recent date and time that the membership user was locked out.</returns>
        public new DateTime LastLockoutDate { get; set; }
        /// <summary>
        /// Gets the date and time when the user was added to the membership data store.
        /// </summary>
        /// <value></value>
        /// <returns>The date and time when the user was added to the membership data store. </returns>
        [Required]
        public new DateTime CreationDate { get; set; }
        /// <summary>
        /// Gets the date and time when the membership user's password was last updated.
        /// </summary>
        /// <value></value>
        /// <returns>The date and time when the membership user's password was last updated.</returns>
        public new DateTime LastPasswordChangedDate { get; set; }
        /// <summary>
        /// Gets whether the user is currently online.
        /// </summary>
        /// <value></value>
        /// <returns>true if the user is online; otherwise, false.</returns>
        [Required]
        public new bool IsOnline { get; set; }
        /// <summary>
        /// Gets the name of the membership provider that stores and retrieves user information for the membership user.
        /// </summary>
        /// <value></value>
        /// <returns>The name of the membership provider that stores and retrieves user information for the membership user.</returns>
        [Required, StringLength(250, MinimumLength = 1)]
        public new string ProviderName { get; set; }
        /// <summary>
        /// Gets or sets the password.
        /// </summary>
        /// <value>The password.</value>
        [Required, StringLength(50, MinimumLength = 1)]
        public string Password { get; set; }
        /// <summary>
        /// Gets or sets the password answer.
        /// </summary>
        /// <value>The password answer.</value>
        public string PasswordAnswer { get; set; }
        /// <summary>
        /// Gets or sets the e-mail address for the membership user.
        /// </summary>
        /// <value></value>
        /// <returns>The e-mail address for the membership user.</returns>
        [Required, StringLength(50, MinimumLength = 1)]
        public override string Email { get { return base.Email; } set { base.Email = value; } }
        /// <summary>
        /// Gets or sets the domain roles.
        /// </summary>
        /// <value>The domain roles.</value>
        public  IList<DomainRole> DomainRoles { get; set; }
    }
}